#from django.template.loader import get_template
#from django.template import Context
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
import datetime

def hello(request):
	ua = request.META.get('HTTP_USER_AGENT', 'unkown')
	return HttpResponse(ua)

def display_meta(request):
	values = request.META.items()
	values.sort()
	return render_to_response('display_meta.html', {'meta':values})

def current_datetime(request):
	if 'offset' in request.GET:
		try:
			hours_offset = int(request.GET['offset'])
			next_time = datetime.datetime.now() + datetime.timedelta(hours=hours_offset)
		except:
			current_date = datetime.datetime.now()
	else:
		current_date = datetime.datetime.now()
	#t = get_template('current_datetime.html')
	#html = t.render(Context({'current_date': now}))
	#return HttpResponse(html)
	#return render_to_response('current_datetime.html', {'current_date': now})
	return render_to_response('current_datetime.html', locals())

def hours_ahead(request, offset):
	#return HttpResponse(request.GET)
	try:
		hours_offset = int(offset)
	except ValueError:
		return Http404()
	next_time = datetime.datetime.now() + datetime.timedelta(hours=hours_offset)
	#dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
	#assert False
	#html = "<html><body>In %s hour(s), It will be %s</body></html>" % (offset, dt)
	#return HttpResponse(html)
	return render_to_response('hours_ahead.html', locals())